import {Continer} from "../continer";

export class TextArea extends Continer {
  constructor() {
    super();
    // 1.创建cavans：大小100%
    this.textAreaDom = document.createElement('div');
    this.textAreaDom.oninput = (event) => {
      this.setSize();
    };
    this.textAreaDom.classList.add('draw-freeBox-item');
    this.textAreaDom.classList.add('draw-freeBox--textarea');
    this.textAreaDom.setAttribute('contenteditable', 'true');
  }

  // 设置容器高度
  setSize() {
    const height = Math.max(this.textAreaDom.scrollHeight, this.continerHeight);
    if (this.continerHeight < height) {
      this.continerHeight = height;
      this.resizeContiner({});
    }
  }

  // 容器创建时
  created() {
  }

  afterResize() {
    this.textAreaDom.focus();
    this.setSize();
  }

  // 容器销毁时
  beforeDestroy() {
    this.paste();
    this.textAreaDom.innerHTML = '';
    this.continer.removeChild(this.textAreaDom);
  }
  readyTool() {
    super.readyTool();
    this.continer.appendChild(this.textAreaDom);
  }
}